if (!localStorage.getItem('token')) {
    alert('请重新登录')
    location.href = './login.html'
}
document.querySelector('.logout').addEventListener('click', () => {
    if (!confirm('是否退出登录?')) return
    localStorage.removeItem('token')
    localStorage.removeItem('username')
    location.href = './login.html'
})
document.querySelector('.user span').innerHTML = localStorage.getItem('username')
document.querySelector('.init').addEventListener('click', async () => {
    const res = await axios({
        url: '/init/data'
    })
    if (res.code == 0) {
        Toast.success('恭喜您，初始化数据成功！')
        setTimeout(() => {
            location.reload()
        }, 1500)
    } else {
        Toast.fail(res.message)
    }
})